package com.study.design.pattern.pattern.behavioral.memento;

/**
 * @Author: gongsl
 * @Date: 2025-03-24 21:58
 */
public class MementoPatternDemo {
    public static void main(String[] args) {
        TextEditor editor = new TextEditor();
        Caretaker caretaker = new Caretaker();

        editor.write("第一版内容");
        // 保存状态
        caretaker.saveState(editor);
        System.out.println("当前文本: " + editor.getText());

        editor.write("第二版内容");
        caretaker.saveState(editor);
        System.out.println("当前文本: " + editor.getText());

        editor.write("第三版未保存内容");
        System.out.println("当前文本: " + editor.getText());

        // 执行撤销操作
        caretaker.undo(editor);
        System.out.println("撤销后文本: " + editor.getText());

        caretaker.undo(editor);
        System.out.println("再次撤销后文本: " + editor.getText());
    }
}
